package com.datastructure.test.findgreatestsumofsubarray2;

import java.util.Arrays;

public class FindGreatestSumOfSubArray {

    public static void main(String[] args) {

    }

    public int[] FindGreatestSumOfSubArray (int[] array) {
        // write code here
        if(array.length==1){
            return array;
        }
        int value=0,max=Integer.MIN_VALUE,start=0,end=0,fs=0,fe=0;
        for(int i=0;i<array.length;i++){
            if(value>=0){
            }else{
                value=0;
                start=i;
            }
            value+=array[i];
            if(max>value){
            }else{
                max=value;
                end=i;
                if(end-start>=fs-fe){
                    fs=start;
                    fe=end;
                }
            }
        }
        return Arrays.copyOfRange(array, fs, fe+1);
    }
}
